from sam.wrapper.CommonWrapper import print_task_cost_time, retry_by_special_exception


def debug(func):
    '''
    不带参数的装饰器
    :param func:
    :return:
    '''

    def wrapper():
        print("[DEBUG]: enter {}()".format(func.__name__))
        return func()

    return wrapper


def logging(level):
    def wrapper(func):
        def inner_wrapper(*args, **kwargs):
            print("[{level}]: enter function {func}()".format(
                level=level,
                func=func.__name__))
            return func(*args, **kwargs)

        return inner_wrapper

    return wrapper


def html_tags(tag_name):
    '''
    带 参数 的装饰器
    :param tag_name:
    :return:
    '''
    print('begin outer function.')

    def wrapper_(func):
        print("begin of inner wrapper function.")

        def wrapper(*args, **kwargs):
            content = func(*args, **kwargs)
            print("<{tag}>{content}</{tag}>".format(tag=tag_name, content=content))

        print('end of inner wrapper function.')
        return wrapper

    print('end of outer function')
    return wrapper_


@print_task_cost_time
@html_tags('b')
def hello(name='Toby'):
    return 'Hello {}!'.format(name)


@retry_by_special_exception()
def ll():
    a = 1 / 0
    print(a)


if __name__ == "__main__":
    ll()
